// pages/auth/auth.js
import { request } from '../../request/index'
import { getSetting, chooseAddress, openSetting, showModal, showToast } from '../../utils/asyncWx'
import regeneratorRuntime from '../../lib/runtime/runtime';
import { login } from '../../utils/asyncWx'
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    async handleGetUserInfo(e) {
        try {
            // 获取用户信息
            const { encryptedData, iv, rawData, signature } = e.detail
            // 获取小程序登录后的code
            const { code } = await login()
            const loginPramas = { encryptedData, iv, rawData, signature, code }
            // 获取用户token
            const { token } = await request({ url: '/users/wxlogin', data: loginPramas, method: 'post' })
            // 把token缓存的本地
            wx.setStorageSync('token', token)
            // 返回上一个页面
            wx.navigateTo({
                delta: 1
            })
        } catch (error) {
            console.log(error);
        }
    }
})